function Node(value){
    this.value= value;
    this.next = null;
}

function createList(len){
    let head = new Node(1);
    let p = head;
    for(let i = 1;i < len;i ++){
        p.next = new Node(i + 1);
        p = p.next;
    }
    return head;
}

function showList(head){
    let p = head;
    while(p){
        console.log(p.value);
        p = p.next;
    }
}

let reverseList = head => {
    let pre = null;
    let cur = head;
    while(cur){
        let next = cur.next;
        cur.next = pre;
        pre = cur;
        cur = next;
    }
    return pre;
}

let reverseList2 = head => {
    let pre = null;
    let cur = head;
    let reverse = (pre, cur) => {
        if(!cur){
            return pre;
        }
        let next = cur.next;
        cur.next = pre;
        pre = cur;
        cur = next;
        return reverse(pre,cur);
    }
    return reverse(pre,cur);
}
export {
    showList,createList,Node,reverseList,reverseList2
}